﻿Imports System.Runtime.CompilerServices
Imports System.Text

''' <summary>
''' StringBuilder拡張メソッド
''' </summary>
''' <remarks>
''' #111 文字列処理の見直し
''' 既存の文字列が空でない場合、区切り文字を追加します
''' </remarks>
Friend Module StringBuilderExtension

    ''' <summary>
    ''' 文字列が存在するかどうかを示します
    ''' </summary>
    ''' <param name="source"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <Extension()>
    Public Function Any(source As StringBuilder) As Boolean
        If source.Length = 0 Then
            Return False
        Else
            Return True
        End If
    End Function

    ''' <summary>
    ''' 区切り文字を追加します
    ''' </summary>
    ''' <param name="source"></param>
    ''' <param name="delimiter">区切り文字</param>
    ''' <returns></returns>
    ''' <remarks>></remarks>
    <Extension()>
    Public Function AppendDelimiter(source As StringBuilder, delimiter As String) As StringBuilder
        If source.Any Then
            source.Append(delimiter)
        End If
        Return source
    End Function
End Module